# 初始化MongoDB客户端
from pymongo import MongoClient

client = MongoClient('mongodb://localhost:27017/')  # 默认连接本地MongoDB
db = client['test']  # 使用test数据库
book_collection = db['book']  # 使用book集合

def premium_recommendations(user_id=None):
    books_cursor = book_collection.aggregate([
        {'$sample': {'size': 10}}  # 随机抽取 10 本书
    ])
    recommendations = []
    for book_data in books_cursor:
        formatted_book = {
            '_id': book_data['_id'],
            'title': book_data.get('title', ''),
            'author': book_data.get('author', ''),
            'cover': book_data.get('cover', '')
        }
        recommendations.append(formatted_book)

    return recommendations
